﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using RedHouse.Data;
using MySubcribeService = RedHouse.Data.Base.SubcribeService;
using RedHouse.Data.Common;
namespace RedHouse.Web.Services
{
    /// <summary>
    /// Summary description for SubcribeService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class SubcribeService : System.Web.Services.WebService
    {    

        [WebMethod]
        public string Subcribe(string email)
        {
            string message = string.Empty;
            if (MySubcribeService.Instance.CheckExistingEmail(email))
            {
                message = "Your email has already been subcribed! Thanks for your subcription!";
                return message;
            }

            Subcribe subcribe = new Subcribe()
            {
                ID = Guid.NewGuid(),
                State = 0,
                Email = email,
                CreatedDate = DateTime.Now,
                CreatedBy = email
            };

            OperationResult result = MySubcribeService.Instance.SaveSubcribe(subcribe);
            message = result.Message;
            return message;
        }
    }
}
